class AddDeterminism < Formula
  desc "Build postprocessor to reset metadata fields for build reproducibility"
  homepage "https://github.com/keszybz/add-determinism"
  url "https://github.com/keszybz/add-determinism/archive/refs/tags/v0.6.0.tar.gz"
  sha256 "289e3586bc9234fc3612a7f7c521b75511fa27f5dcba8b04825249ca03880f80"
  license "GPL-3.0-or-later"

  no_autobump! because: :requires_manual_review

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_linux:  "3cc67f0631eb00dd69bf152dfc64d4d97d690c1f164eb821af61b3e22864212c"
    sha256 cellar: :any_skip_relocation, x86_64_linux: "0e31f9976fa0c9dcb2d0606af4d84512a9b65392d4f66d208590f2a3c1e4c8ec"
  end

  depends_on "rust" => :build
  depends_on :linux
  depends_on "zlib"

  def install
    system "cargo", "install", *std_cargo_args
  end

  test do
    (testpath/"test.html").write <<~EOS
      <!-- Generated by javadoc (1.2.3) on 2025-01-01 -->
      <meta name="dc.created" content="2025-01-01">
    EOS

    ENV["SOURCE_DATE_EPOCH"] = "0"
    system bin/"add-determinism", testpath/"test.html"

    assert_match "<!-- Generated by javadoc -->", (testpath/"test.html").read
    assert_match "content=\"1970-01-01\"", (testpath/"test.html").read
  end
end
